package com.ld.xxssglxt.controller;

import com.ld.xxssglxt.pojo.Admin;
import com.ld.xxssglxt.pojo.LoginPojo;
import com.ld.xxssglxt.service.AdminService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 登录和注销等操作
 */
@RestController // 所有接口都不使用页面模板
public class LoginController {
    @Resource
    private AdminService adminService;
    @RequestMapping(value = "/login", method = RequestMethod.POST)
//    public Object login(String account, String password, String role) {
    //@RequestBody 表示接收是的Json格式的参数
    public Object login(@RequestBody LoginPojo loginPojo) {
        System.out.println("login:" + loginPojo);
        Object bean = null;
        if (loginPojo.getRole().equalsIgnoreCase("0")) {
            bean = adminService.login(loginPojo.getAccount(), loginPojo.getPassword());
            System.out.println(bean);
        } else if (loginPojo.getRole().equalsIgnoreCase("1")) {

        } else if (loginPojo.getRole().equalsIgnoreCase("2")) {

        }
        if (bean == null) {
            return "登录失败";
        }
        return "登录成功";
    }
}
